/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ve.usb.cep.db;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;


/**
 *
 * @author Gimbet
 */
public class Session {
  protected static Connection c = null;

  public static Connection connection(){
      if (null == c){
          Session.connect();
      }
      return c;
  }
    
  protected static void connect(){

    try {
      Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e) {
      System.out.println("Couldn't find the driver!");
      System.out.println("Let's print a stack trace, and exit.");
      e.printStackTrace();
      System.exit(1);
    }

    try {
      c = DriverManager.getConnection(
          "jdbc:postgresql://localhost:5432/cep", "cep", "123456"
      );
    } catch (SQLException se) {
      System.out.println("Couldn't connect: print out a stack trace and exit.");
      se.printStackTrace();
      System.exit(1);
    }
  }
}

